# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=gpgme
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.11.1
pkgrel=1
pkgdesc="A C wrapper library for GnuPG (mingw-w64)"
arch=('any')
url="https://gnupg.org/related_software/gpgme/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnupg"
         "${MINGW_PACKAGE_PREFIX}-libassuan"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-npth"
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-qt5"
             "doxygen")
options=('!emptydirs') # '!strip' 'debug')
source=("https://www.gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig}
        0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch
        0003-mingw-mkstemp.patch
        0004-gpgme-find-gnupg.patch
        0005-invoke-scripts-via-sh.patch
        0006-fix-building-docs.patch)
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6'
              '46CC730865BB5C78EBABADCF04376F3EE0856959'
              '031EC2536E580D8EA286A9F22071B08A33BD3F06'
              'D238EA65D64C67ED4C3073F28A861B1C7EFD60D9')
sha256sums=('2d1b111774d2e3dd26dcd7c251819ce4ef774ec5e566251eb9308fa7542fbd6f'
            'SKIP'
            '55104d95bb37ed83929415603a610ce1da8ec83d9d4de09222822f21045dcda4'
            'b89dabf440414ea02ae3f8249d5db3ff85cc5ac76f70037d6efc1890cab1985b'
            '71763a209761afe6495d3d85e25bbe6ba76348450d426f8a2618a34a264e058a'
            'dd2cf257761781a1d8e5bfac7fcc09633e09928dd9a13cb509a5b76fd44aea2d'
            'b56fe3e3da872ca84d08b4aa426e6f71b3227e2a253bc45bf6023abf1288ecc9')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch
  #patch -p1 -i "${srcdir}"/0003-mingw-mkstemp.patch
  patch -p1 -i "${srcdir}"/0004-gpgme-find-gnupg.patch
  patch -p1 -i "${srcdir}"/0005-invoke-scripts-via-sh.patch
  patch -p1 -i "${srcdir}"/0006-fix-building-docs.patch

  autoreconf -ivf
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  # mingw doxygen can't wrok with UNIX paths in doxyfile
  DOXYGEN=/usr/bin/doxygen \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --libexecdir=${MINGW_PREFIX}/bin \
    --disable-fd-passing \
    --enable-shared \
    --enable-static \
    --disable-gpgsm-test

  make
}

check() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  #make check
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
